package edu.qd.learn.newchapter.chapter_thread.day02;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author 布衣
 */
public class ThirdPool02 extends Thread {

    public static volatile int ticket = 1;

    @Override
    public void run() {
        //同步代码块
        if (ticket < 101) {
            System.out.println(getName() + "正在出售第" + ticket++ + "张票");
        }
    }

    public ThirdPool02() {

    }

    public ThirdPool02(String name) {
        super(name);
    }

    public static void main(String[] args) {
        ThirdPool02 t1 = new ThirdPool02("窗口1");
        ThirdPool02 t2 = new ThirdPool02("窗口2");
        ThirdPool02 t3 = new ThirdPool02("窗口3");
        ThirdPool02 t4 = new ThirdPool02("窗口4");
        ThirdPool02 t5 = new ThirdPool02("窗口5");
        ExecutorService es = Executors.newSingleThreadExecutor();

        es.execute(t4);
        es.shutdown();
    }

}